package jee.boot.data.permission.config;

/**
 * 权限拦截
 */
public class AuthInterceptorThreadContext {
    /**
     * 权限拦截器线程开关
     */
    private static ThreadLocal<Boolean> permissionFlag=new ThreadLocal<Boolean>(){
        @Override
        protected Boolean initialValue() {
            return new Boolean(true);
        }
    };

    /**
     * 线程内开启拦截,后面的请求都会经过权限拦截
     */
    public static void enableAuthPermission(){
        permissionFlag.set(true);
    }

    /**
     * 线程内关闭拦截,后面的请求都不会经过权限拦截
     */
    public static void disableAuthPermission(){
        permissionFlag.set(false);
    }

    /**
     * 手动设置
     * @param flag
     */
    public static void setAuthPermission(Boolean flag){
        permissionFlag.set(flag);
    }
    /**
     * 判断是否需要经过权限拦截器
     * @return
     */
    public static Boolean isAuthPermission(){
        return permissionFlag.get();
    }
}
